;
(function (call) {
    var main = {
        userInfo: null,
        mapId: "jcybMap",
        init: function () {
            this.initView();
            this.bindEvt();
        },
        initView: function () {
            var userInfo = $("#userInfo").data('info');
            this.userInfo = userInfo;
            var time = new Date().format("yyyy-MM-dd hh:mm");
            this.time = CafeJS.Datepicker({
                appendTo: "#addTime",
                type: 1,
                dateFmt: "yyyy-MM-dd hh:mm",
                curDate: time
            });
            this.getAreaData();
        },
        // 获取区域数据
        getAreaData: function () {
            var that = this;
            $.getJSON(api.internal.business.getAreaData, function (res) {
                if (res.isSuccess) {
                    var data = res.data;
                    for (var i = 0; i < data.length; i++) {
                        if (Number(that.userInfo.userAreaCode) === data[i].areaId) {
                            $("#addEventUnit").val(data[i].areaName);
                        }
                    }
                }
            });
        },
        // 保存
        saveEvent: function () {
            var that = this;
            var name = $("#file").val();
            var hzm = name.substr(name.indexOf(".") + 1);
            if (name == '') {
                alert('请选择需要上传的文件');
            } else if (hzm != "zip") {
                alert('请选择zip格式的文件');
            } else {
                var forData = new FormData();
                forData.append('file', $('#file')[0].files[0]);
                forData.append("monitorTime", $("#addTime").text() + ':00');
                forData.append("type", $("#addEventType option:selected").text());
                forData.append("name", $("#eventName").val());
                forData.append("disaster", $("#relatedDisasters").val());
                forData.append("monitorDesc", $("#eventResume").val());
                forData.append("createUser", that.userInfo.smuser.name);
                forData.append("iid", that.userInfo.smuser.iid);
                loading.add('#modal_add_event');
                $.ajax({
                    url: api.internal.business.otherMonitorCreate,
                    type: "POST",
                    data: forData,
                    dataType: 'json',
                    cache: false,
                    processData: false,
                    contentType: false,
                    xhrFuelds: {
                        withCredentials: true,
                    },
                    crossDomain: true,
                    success: function (res) {
                        loading.remove();
                        if (res.isSuccess) {
                            alert("上传成功");
                            $("#file-text").text('').removeAttr('title');
                            $("#file").val('');
                            $("#modal_add_event .close").trigger('click');
                        } else {
                            alert("上传失败");
                        }
                    }
                })
            }
        },
        bindEvt: function () {
            var that = this;
            $("#file").change(function () {
                var val = $("#file").val();
                $("#file-text").text(val).attr('title', val);
            })
            $(".add-monitor-btn #sureBtn").click(function () {
                that.saveEvent();
            })
            $("#cancelBtn").click(function () {
                $("#modal_add_event .close").trigger('click');
            })
        },
        //弹出框内容
        alert: function (info) {
            $.dialogMaster({
                "type": 'tip',
                "info": info
            });
        },
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    CafeJS.models(['datepicker'], function () {
        main.init();
    });
});